package geektime.concurrent.part2.blockingqueuedemo;

import java.util.concurrent.BlockingQueue;

public class NumberConsumer implements Runnable {
    private BlockingQueue<Integer> queue;

    private int diamondNumber;

    public NumberConsumer(BlockingQueue queue, int diamondNumber) {
        this.queue = queue;
        this.diamondNumber = diamondNumber;
    }

    @Override
    public void run() {
        while(true) {
            try {
                Integer number = queue.take();
                if (diamondNumber == number) {
                    System.out.println(Thread.currentThread().getName() + " take the diamond: " + number);
                    return;
                }
//                System.out.println(Thread.currentThread().getName() + " take: " + number);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
